package com.itheima.homework.homework5;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Demo5 {
    public static void main(String[] args) {
        // Map.of("1930", "乌拉圭","1934", "意大利","1938", "意大利","1950","乌拉圭","1954", "西德","1958", "巴西","1962", "巴西","1966", "英格兰","1970","巴西","1974","西得","1978","阿根延");
        Map<String, String> countryMap = Map.ofEntries(Map.entry("1930", "乌拉圭"), Map.entry("1934", "意大利"), Map.entry("1938", "意大利"),
                Map.entry("1950", "乌拉圭"), Map.entry("1954", "西德"), Map.entry("1958", "巴西"),
                Map.entry("1962", "巴西"), Map.entry("1966", "英格兰"), Map.entry("1970", "巴西"),
                Map.entry("1974", "西得"), Map.entry("1978", "阿根廷"), Map.entry("1982", "意大利"),
                Map.entry("1986", "阿根廷"), Map.entry("1990", "西得"), Map.entry("1994", "巴西"),
                Map.entry("1998", "法国"), Map.entry("2002", "巴西"), Map.entry("2006", "意大利"),
                Map.entry("2010", "西班牙"), Map.entry("2014", "德国"), Map.entry("2018", "法国"));
        Map<String, String> map = new HashMap<>(countryMap);
        Scanner sc = new Scanner(System.in);
        lo:
        while (true) {
            System.out.println("请输入您要进行的操作【1:根据年份,2:根据国家,3:退出】");
            int choice = sc.nextInt();
            switch (choice) {
                case 1:
                    getCountryByYear(map);

                    break;
                case 2:
                    getYearByCountry(map);
                    break;
                case 3:
                    break lo;
                default:
                    System.out.println("您的输入有误");


            }

        }


    }

    private static void getYearByCountry(Map<String, String> map) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入国家：");
        String countrySc = sc.next();
        boolean countryScFlag = map.containsValue(countrySc);
        if (countryScFlag == true) {
            System.out.println(countrySc + "获得世界杯的年份是：");
            map.forEach((String key, String vaule) -> {
                if (vaule.equals(countrySc)) {
                    System.out.println(key);
                }
            });

        } else {
            System.out.println(countrySc + "没有获得过世界杯冠军");
            return;
        }
    }

    private static void getCountryByYear(Map<String, String> map) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入年份：");
        String yearSc = sc.next();
        boolean yearFlag = map.containsKey(yearSc);
        if (yearFlag == true) {
            String country = map.get(yearSc);
            System.out.println(yearSc + "年的世界杯冠军是:" + country);
        } else {
            System.out.println(yearSc + "年没有举办世界杯");
            return;
        }
    }
}
